define([
    "UtilDir/util",
    "UtilDir/tool",
    "UtilDir/org/selectOrg",
    "UtilDir/searchBlock",
    "Date", "DateCN", "css!DateCss",
    "EasyUI", "EasyUI-lang"
], function (Util, Tool, SelectOrg, SearchBlock) {

    var sysPath = getServer() + "/static/app/cdqh/qhdrilloverview";
    var qhDrillFormHtml = sysPath + "/views/qhDrillForm.html";
    var qhDrillOverviewFormHtml = sysPath + "/views/qhDrillOverviewForm.html";
    var qhLithologyFormHtml = sysPath + "/views/qhLithologyForm.html";
    var qhStandardPenetrationFormHtml = sysPath + "/views/qhStandardPenetrationForm.html";
    var qhShearWaveFormHtml = sysPath + "/views/qhShearWaveForm.html";
    var qhSoilDynamicFormHtml = sysPath + "/views/qhSoilDynamicForm.html";
    var qhSiteCategoryFormHtml = sysPath + "/views/qhSiteCategoryForm.html";
    var getQhDrillOverviewController = function () {
        return getServer() + "/qh/qhY02";
    };
    var QhY04Controller = function () {
        return getServer() + "/qh/qhY04";
    };
    var QhY05Controller = function () {
        return getServer() + "/qh/qhY05";
    };
    var QhY06Controller = function () {
        return getServer() + "/qh/qhY06";
    };
    var QhY08Controller = function () {
        return getServer() + "/qh/qhY08";
    };
    var QhY18Controller = function () {
        return getServer() + "/qh/qhY18";
    };
    var getMutipleSheetPoiController = function () {
        return getServer() + "/qh/drill";
    };
    var idsArr1 = [];

    /**
     * 页面初始化
     */
    var init = function () {
        initSearchBlock();
        queryBtnBind();
        initcreateProvince();
        //initReviewStatusSelect();
        //initDrillCode();
        createQhDrillOverviewGrid();
    };

    var initDrillCode = function () {
        var drillCode = window.sessionStorage.getItem("drillJumpId");
        if (drillCode && drillCode.length > 0) {
            $("#drillCodeCondition").val(drillCode);
            window.sessionStorage.setItem("drillJumpId", "");
        }
    };

    var initcreateProvince = function () {
        var html = "";
        $("#citySelect").append(html);
        $("#areaSelect").append(html);
        $.ajax({
            url: getServer() + "/divisions/root/subdivisions",
            contentType: "application/json",
            type: "get",
            success: function (data) {
                $.each(data, function (idx, item) {
                    html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                });
                $("#provinceSelect").append(html);
            }
        });
        $("#provinceSelect").change(function () {
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#citySelect option").remove();
            $("#citySelect").append(html);
            $("#areaSelect option").remove();
            $("#areaSelect").append(html);
            var divisionId = $(this).find("option:selected").attr("exid");
            if ($(this).val() == "北京市" || $(this).val() == "天津市" || $(this).val() == "上海市" || $(this).val() == "重庆市") {
                $("#citySelect").append("<option value='" + $(this).val() + "' exid='" + divisionId + "'>" + $(this).val() + "</option>");
                return;
            }
            $.ajax({
                url: getServer() + "/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#citySelect").append(html);
                }
            });
        });
        $("#citySelect").change(function () {
            if ($(this).val() == "") return;
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#areaSelect option").remove();
            $("#areaSelect").append(html);
            var divisionId = $(this).find("option:selected").attr("exid");
            $.ajax({
                url: getServer() + "/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#areaSelect").append(html);
                }
            });
        });
    }
    var initcreateProvinceForm = function () {
        var html = "";
        $("#city").append(html);
        $("#area").append(html);
        $.ajax({
            url: getServer() + "/divisions/root/subdivisions",
            contentType: "application/json",
            type: "get",
            success: function (data) {
                $.each(data, function (idx, item) {
                    html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                });
                $("#province").append(html);
            }
        });
        $("#province").change(function () {
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#city option").remove();
            $("#city").append(html);
            $("#area option").remove();
            $("#area").append(html);
            var divisionId = $(this).find("option:selected").attr("exid");
            if ($(this).val() == "北京市" || $(this).val() == "天津市" || $(this).val() == "上海市" || $(this).val() == "重庆市") {
                $("#city").append("<option value='" + $(this).val() + "' exid='" + divisionId + "'>" + $(this).val() + "</option>");
                return;
            }
            $.ajax({
                url: getServer() + "/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#city").append(html);
                }
            });
        });
        $("#city").change(function () {
            if ($(this).val() == "") return;
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#area option").remove();
            $("#area").append(html);
            var divisionId = $(this).find("option:selected").attr("exid");
            $.ajax({
                url: getServer() + "/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#area").append(html);
                }
            });
        });
    };

    var initReviewStatusSelect = function () {
        $.ajax({
            url: getQhDrillOverviewController() + "/getValidDictItemsByDictCode/" + "reviewStatusSelect",
            type: "get",
            success: function (data) {
                var mySelect = document.getElementById("reviewStatusSelect");
                mySelect.add(new Option("请选择", ''), 0);
                for (var i = 0; i < data.length; i++) {
                    var name = data[i].dictItemName;
                    var code = data[i].dictItemCode;
                    mySelect.add(new Option(name, code));
                }
            }
        });
    };

    var initProjectCompleteDate = function () {
        $("#projectCompleteDate").datetimepicker({
            //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
            language: "cn",
            //输出格式化
            format: 'yyyy-mm-dd',
            //直接选择‘今天’
            todayBtn: true,
            //设置最精确的时间选择视图
            minView: 'month',
            //高亮当天日期
            todayHighlight: true,
            //显示“上午”“下午”
            showMeridian: true,
            //选择完毕后自动关闭
            autoclose: true
        });
    };
    var initConstructionStartDate = function () {
        $("#constructionStartDate").datetimepicker({
            //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
            language: "cn",
            //输出格式化
            format: 'yyyy-mm-dd',
            //直接选择‘今天’
            todayBtn: true,
            //设置最精确的时间选择视图
            minView: 'month',
            //高亮当天日期
            todayHighlight: true,
            //显示“上午”“下午”
            showMeridian: true,
            //选择完毕后自动关闭
            autoclose: true
        });
    };

    var initConstructionReportDate = function () {
        $("#constructionReportDate").datetimepicker({
            //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
            language: "cn",
            //输出格式化
            format: 'yyyy-mm-dd',
            //直接选择‘今天’
            todayBtn: true,
            //设置最精确的时间选择视图
            minView: 'month',
            //高亮当天日期
            todayHighlight: true,
            //显示“上午”“下午”
            showMeridian: true,
            //选择完毕后自动关闭
            autoclose: true
        });
    };

    var initSearchBlock = function () {
        SearchBlock.init("searchBlock");

    };
    var queryBtnBind = function () {

        $("#btnSearch").click(function () {
            createQhDrillOverviewGrid();
        });
        $("#btnReset").click(function () {
            $("#provinceSelect").val("");
            $("#citySelect").val("");
            $("#areaSelect").val("");
            $("#village").val("");
            $("#drillSynthesizeCode").val("");
            $("#dataState").val("");
            $("#dataSourceType").val("");
        });
        $("#btnExport").click(function () {
            exportFunc();
        });
    };
    var exportFunc = function () {
        var province= $("#provinceSelect").val();
        var city= $("#citySelect").val();
        var area= $("#areaSelect").val();
        var village= $("#village").val();
        var drillSynthesizeCode= $("#drillSynthesizeCode").val();
        var dataState= $("#dataState").val();
        var dataSourceType= $("#dataSourceType").val();
        window.location.href =getMutipleSheetPoiController() + "/exportMultiSheets?"+"province="+province+"&city="+city+"&area="+area+"&village="+village+"&drillSynthesizeCode="+drillSynthesizeCode+"&dataState="+dataState+"&dataSourceType="+dataSourceType;
            /*$.ajax({
            url: getMutipleSheetPoiController() + "/exportMultiSheets/",
            contentType: "application/json",
            type: "post",
            data:JSON.stringify(queryParams),
            success:function (data) {
            Util.alert(data.message);
            //createQhDrillOverviewGrid();
        }
    });*/
    }
    var createQhDrillOverviewGrid = function () {
        $("#qhDrillOverviewGrid").datagrid({
            url: getQhDrillOverviewController() + "/queryQhY02s",
            method: "GET",
            fitColumns: true,
            autoRowHeight: false,
            idField: 'id',
            columns: [[
                {field: "ck", checkbox: true},
                {
                    field: 'drillSynthesizeCode',
                    title: '钻孔综合编号',
                    width: '10%',
                    sortable: true,
                    align: 'center',

                },
                {
                    field: 'drillDependProject',
                    title: '钻孔依托的项目',
                    width: '10%',
                    align: 'center',

                },
                {
                    field: 'projectCompleteInstitution',
                    title: '项目完成单位',
                    width: '10%',
                    align: 'center',

                },
                {
                    field: 'projectCompleteDate',
                    title: '项目完成时间',
                    width: '8%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'province',
                    title: '钻孔所在省级行政区',
                    width: '11%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'city',
                    title: '钻孔所在地市级行政区',
                    width: '11%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'area',
                    title: '钻孔所在区（县）级行政区',
                    width: '11%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'village',
                    title: '钻孔所在乡级行政区',
                    width: '10%',
                    align: 'center',
                },
                {
                    field: 'longitude',
                    title: '孔位经度（°）',
                    width: '8%',
                    align: 'center',
                    formatter: function (value, rowData, rowIndex) {
                        if (idsArr1.indexOf(rowData.id) != "-1") {
                            return '<span style="color: red;"> ' + rowData.longitude + ' </span> '
                        } else {
                            return rowData.longitude
                        }

                    }
                },
                {
                    field: 'latitude',
                    title: '孔位纬度（°）',
                    width: '8%',
                    align: 'center',
                    formatter: function (value, rowData, rowIndex) {
                        if (idsArr1.indexOf(rowData.id) != "-1") {
                            return '<span style="color: red;"> ' + rowData.latitude + ' </span> '
                        } else {
                            return rowData.latitude
                        }

                    }
                },
                {
                    field: 'updateTime',
                    title: '数据修改时间',
                    width: '10%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'dataState',
                    title: '数据状态',
                    width: '8%',
                    align: 'center',
                    formatter: function (value) {
                        if (value == "0") {
                            return '未质检';
                        } else if (value == "1") {
                            return '自动质检不通过';
                        } else if (value == "2") {
                            return '自动质检通过';
                        } else if (value == "3") {
                            return '人工质检不通过';
                        } else if (value == "4") {
                            return '人工质检通过';
                        }
                    }
                },
                {
                    field: 'operation', title: '操作', width: '8%', align: 'center',
                    formatter: function (value, rowData, rowIndex) {
                        return '<a href="javascript:void(0);" onclick="_editQhDrillOverview(\'' + rowData.id + "','" + rowData.dataState + '\');">查看表单</a> '
                    }
                }
            ]],
            toolbar: [{
                iconCls: 'fa fa-plus-circle',
                text: "添加",
                handler: function () {
                    addQhDrillOverview();
                }
            }, {
                iconCls: 'fa fa-trash-o',
                text: "删除",
                handler: function () {
                    deleteQhDrillOverview();
                }
            }, {
                iconCls: 'fa fa-upload',
                text: "导入",
                handler: function () {
                    importForm();

                }
            }, {
                iconCls: 'fa fa-download',
                text: "导出",
                handler: function () {
                    exportForm();
                }
            },
//	        {
//              iconCls: 'fa fa-check-circle',
//              text:"坐标精度校验",
//              handler: function(){
//                  check1();
//              }
//         	},
                {
                    iconCls: 'fa fa-check-circle',
                    text: "系统自动质检",
                    handler: function () {
                        systemCheck();
                    }
                }],
            queryParams: {
                province: $("#provinceSelect").val(),
                city: $("#citySelect").val(),
                area: $("#areaSelect").val(),
                village: $("#village").val(),
                drillSynthesizeCode: $("#drillSynthesizeCode").val(),
                dataState: $("#dataState").val(),
                dataSourceType: $("#dataSourceType").val()
            },
            pagination: true,
            pageSize: 10
        });
    };
    //校验
    var check1 = function () {
        var rows = $("#qhDrillOverviewGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        }
//      if (rows.length >= 1) {
//          for (var i = 0; i < rows.length; i++) {
//              if (rows[i].reviewStatus != '1') {
//                  Util.alert("只有数据状态为已提交的才能校验!");
//                  return;
//              }
//          }
//      }
        Util.confirm("是否要校验选中的表单?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";
            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: getQhDrillOverviewController() + "/checkCoordinate/" + ids,
                contentType: "application/json",
                type: "POST",
                success: function (data) {
                    idsArr1 = data.data;
                    Util.alert(data.message);
                    createQhDrillOverviewGrid();
                }
            });
        }, function () {
            return;
        });

    };
    //系统自动质检
    var systemCheck = function () {
        var rows = $("#qhDrillOverviewGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        }
        if (rows.length >= 1) {
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].dataState == '4') {
                    Util.alert("只能对数据状态不为【人工质检通过】的钻孔数据进行系统自动质检!");
                    return;
                }
            }
        }
        Util.confirm("是否要质检选中的表单?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";
            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: getQhDrillOverviewController() + "/dataQualityCheck/" + ids,
                contentType: "application/json",
                type: "POST",
                success: function (res) {
                    //Util.alert(res.mag);
                    if (JSON.stringify(res) == "{}") {
                        createQhDrillOverviewGrid();
                        Util.alert("系统自动质检通过");

                    } else {
                        createQhDrillOverviewGrid();
                        Util.alert(res.mag + "系统自动质检不通过");

                    }
                    createQhDrillOverviewGrid();
                }
            });
        }, function () {
            return;
        });

    };
    var formValidator = function () {
        //自定义validate验证输入的数字小数点后保留至少4位
        jQuery.validator.addMethod("maxNumber", function (value, element) {
            var returnVal = true;
            inputZ = value;
            var ArrMen = inputZ.split(".");    //截取字符串
            if (ArrMen.length == 2) {
                if (ArrMen[1].length < 4) {    //判断小数点后面的字符串长度
                    returnVal = false;
                    return false;
                }
            }
            return returnVal;
        }, "小数点后保留至少4位");         //验证错误信息
        $("#qhDrillForm").validate({
            rules: {
                drillSynthesizeCode: {
                    required: true,
                    rangelength: [12, 12]
                },
                drillDependProject: {
                    required: true,
                },
                projectCompleteInstitution: {
                    required: true,
                },
                projectCompleteDate: {
                    required: true,
                },
                projectPrincipal: {
                    required: true,
                },
                drillConstructionInstitution: {
                    required: true,
                },
                drillConstructionPrincipal: {
                    required: true,
                },
                constructionStartDate: {
                    required: true,
                },
                constructionReportDate: {
                    required: true,
                },
                drillCode: {
                    required: true,
                },
                drillX: {
                    required: false,
                    number: true
                },
                drillY: {
                    required: false,
                    number: true
                },
                longitude: {
                    required: true,
                    number: true,
                    maxNumber: true,
                    range: [73.0000, 136.0000]
                },
                latitude: {
                    required: true,
                    number: true,
                    maxNumber: true,
                    range: [5.0000, 54.0000]
                },
                drillDepth: {
                    required: true,
                    number: true,
                    min: 0,
                },
                elevation: {
                    required: true,
                    number: true
                },
                stableWaterDepth: {

                    number: true
                },
                province: {
                    required: true,
                },
                city: {
                    required: true,
                },
                area: {
                    required: true,
                },
                village: {
                    required: true,
                },
            },
            messages: {
                drillSynthesizeCode: {
                    required: "钻孔综合编号不允许为空!",
                    rangelength: "长度为12位!"
                },
                drillDependProject: {
                    required: "钻孔依托的项目不允许为空!",
                },
                projectCompleteInstitution: {
                    required: "项目完成单位不允许为空!",
                },
                projectCompleteDate: {
                    required: "项目完成时间不允许为空!",
                },
                projectPrincipal: {
                    required: "项目负责人不允许为空!",
                },
                drillConstructionInstitution: {
                    required: "钻孔勘察单位不允许为空!",
                },
                drillConstructionPrincipal: {
                    required: "钻孔勘察负责人不允许为空!",
                },
                constructionStartDate: {
                    required: "勘察施工日期不允许为空!",
                },
                constructionReportDate: {
                    required: "勘察报告日期不允许为空!",
                },
                drillCode: {
                    required: "钻孔编号不允许为空!",
                },
                longitude: {
                    required: "钻孔坐标经度值不允许为空!",
                    range: "73.0000~136.0000之间"
                },
                latitude: {
                    required: "钻孔坐标纬度值不允许为空!",
                    range: "5.0000~54.0000之间"
                },
                drillDepth: {
                    required: "钻孔深度（m）不允许为空!",
                },
                elevation: {
                    required: "地面高程（m）不允许为空!",
                },
                stableWaterDepth: {
                    required: "稳定水位深度（m）不允许为空!",
                },
                province: {
                    required: "钻孔所在省级行政区不允许为空!",
                },
                city: {
                    required: "钻孔所在地市级行政区不允许为空!",
                },
                area: {
                    required: "钻孔所在区（县）级行政区不允许为空!",
                },
                village: {
                    required: "钻孔所在乡级行政区不允许为空!",
                },

            }
        });
    };
    var formValidatorY04 = function () {
        //自定义validate验证输入的数字小数点位数不能大于两位
        jQuery.validator.addMethod("minNumber", function (value, element) {
            var returnVal = true;
            inputZ = value;
            var ArrMen = inputZ.split(".");    //截取字符串
            if (ArrMen.length == 2) {
                if (ArrMen[1].length > 2) {    //判断小数点后面的字符串长度
                    returnVal = false;
                    return false;
                }
            }
            return returnVal;
        }, "小数点后最多为两位");         //验证错误信息
        jQuery.validator.addMethod("isInteger", function (value, element) {
            return this.optional(element) || (/^[-\+]?\d+$/.test(value) && parseInt(value) >= 0);
        }, "必须为正整数");
        $("#qhLithologyForm").validate({
            rules: {
                assiseNumber: {
                    required: true,
                    isInteger: true    //调用自定义验证
                },
                assiseCode: {
                    maxlength: 20
                },
                formationAge: {
                    required: true,
                    maxlength: 20
                },
                causeAge: {
                    maxlength: 20
                },
                bottomDepth: {
                    required: true,
                    number: true,
                    minNumber: true
                },
                layerThickness: {
                    required: true,
                    number: true,
                    minNumber: true
                },
                geotechnicalName: {
                    required: true,
                    maxlength: 20
                },
                geotechnicalCharacteristics: {
                    required: true,
                    maxlength: 1000
                },

            },
            messages: {
                assiseNumber: {
                    required: "地层序号不允许为空!",
                },
                assiseCode: {

                    maxlength: "不多于20个字符"
                },
                formationAge: {
                    required: "地层年代不允许为空!",
                    maxlength: "不多于20个字符"
                },
                causeAge: {
                    maxlength: "不多于20个字符"
                },
                bottomDepth: {
                    required: "层底深度（m）不允许为空!",
                },
                layerThickness: {
                    required: "分层厚度（m）不允许为空!",
                },
                geotechnicalName: {
                    required: "岩土名称不允许为空!",
                    maxlength: "不多于20个字符"
                },
                geotechnicalCharacteristics: {
                    required: "岩土特征不允许为空!",
                    maxlength: "不多于1000个字符"
                },

            }
        });
    };
    var formValidatorY05 = function () {
        //自定义validate验证输入的数字小数点位数不能大于两位
        jQuery.validator.addMethod("minNumber", function (value, element) {
            var returnVal = true;
            inputZ = value;
            var ArrMen = inputZ.split(".");    //截取字符串
            if (ArrMen.length == 2) {
                if (ArrMen[1].length > 2) {    //判断小数点后面的字符串长度
                    returnVal = false;
                    return false;
                }
            }
            return returnVal;
        }, "小数点后最多为两位");         //验证错误信息

        $("#qhStandardPenetrationForm").validate({
            rules: {
                standardStartDepth: {
                    number: true,
                    min: 0,
                    minNumber: true
                },
                standardEndDepth: {
                    number: true,
                    min: 0,
                    minNumber: true
                },
                standardNumber: {
                    number: true,
                    min: 0,
                    minNumber: true
                },

            },
            messages: {
                standardStartDepth: {},
                standardEndDepth: {},
                standardNumber: {},

            }
        });
    };
    var formValidatorY06 = function () {
        //自定义validate验证输入的数字小数点位数不能大于两位
        jQuery.validator.addMethod("minNumber", function (value, element) {
            var returnVal = true;
            inputZ = value;
            var ArrMen = inputZ.split(".");    //截取字符串
            if (ArrMen.length == 2) {
                if (ArrMen[1].length > 2) {    //判断小数点后面的字符串长度
                    returnVal = false;
                    return false;
                }
            }
            return returnVal;
        }, "小数点后最多为两位");         //验证错误信息
        jQuery.validator.addMethod("isInteger", function (value, element) {
            return this.optional(element) || (/^[-\+]?\d+$/.test(value) && parseInt(value) >= 0);
        }, "必须为正整数");
        $("#qhShearWaveForm").validate({
            rules: {
                code: {
                    required: true,
                    isInteger: true    //调用自定义验证
                },
                geotechnicalDesignation: {
                    required: true,
                    maxlength: 20
                },
                bottomDepth: {
                    required: true,
                    number: true,
                    minNumber: true
                },
                layerThickness: {
                    required: true,
                    number: true,
                    minNumber: true
                },
                shearWaveVelocity: {
                    required: true,
                    number: true,
                    minNumber: true
                },

            },
            messages: {
                code: {
                    required: "序号不允许为空!",
                },
                geotechnicalDesignation: {
                    required: "岩土性名称不允许为空!",
                    maxlength: "不多于20个字符"
                },
                bottomDepth: {
                    required: "层底深度（m）不允许为空!",
                },
                layerThickness: {
                    required: "层厚（m）不允许为空!",
                },
                shearWaveVelocity: {
                    required: "剪切波波速V（m/s）不允许为空!",
                },

            }
        });
    };
    var formValidatorY08 = function () {
        //自定义validate验证输入的数字小数点位数不能大于两位
        jQuery.validator.addMethod("minNumber", function (value, element) {
            var returnVal = true;
            inputZ = value;
            var ArrMen = inputZ.split(".");    //截取字符串
            if (ArrMen.length == 2) {
                if (ArrMen[1].length > 2) {    //判断小数点后面的字符串长度
                    returnVal = false;
                    return false;
                }
            }
            return returnVal;
        }, "小数点后最多为两位");         //验证错误信息
        jQuery.validator.addMethod("minNumber5", function (value, element) {
            var returnVal = true;
            inputZ = value;
            var ArrMen = inputZ.split(".");    //截取字符串
            if (ArrMen.length == 2) {
                if (ArrMen[1].length > 5) {    //判断小数点后面的字符串长度
                    returnVal = false;
                    return false;
                }
            }
            return returnVal;
        }, "小数点后最多为五位");         //验证错误信息
        jQuery.validator.addMethod("isInteger", function (value, element) {
            return this.optional(element) || (/^[-\+]?\d+$/.test(value) && parseInt(value) >= 0);
        }, "必须为正整数");
        $("#qhSoilDynamicForm").validate({
            rules: {
                code: {
                    isInteger: true    //调用自定义验证
                },

                specimenCode: {
                    maxlength: 20
                },
                specimenStartDepth: {
                    number: true,
                    minNumber: true
                },
                specimenEndDepth: {
                    number: true,
                    minNumber: true
                },
                soilName: {
                    maxlength: 20
                },
                naturalDensity: {
                    number: true,
                    minNumber: true
                },

                modulusShearStrain005: {
                    minNumber5: true,
                    number: true
                },
                modulusShearStrain010: {
                    minNumber5: true,
                    number: true
                },
                modulusShearStrain050: {
                    minNumber5: true,
                    number: true
                },
                modulusShearStrain100: {
                    minNumber5: true,
                    number: true
                },
                modulusShearStrain500: {
                    minNumber5: true,
                    number: true
                },
                modulusShearStrain1000: {
                    minNumber5: true,
                    number: true
                },
                modulusShearStrain5000: {
                    minNumber5: true,
                    number: true
                },
                modulusShearStrain10000: {
                    minNumber5: true,
                    number: true
                },
                dampShearStrain005: {
                    minNumber5: true,
                    number: true
                },
                dampShearStrain010: {
                    minNumber5: true,
                    number: true
                },
                dampShearStrain050: {
                    minNumber5: true,
                    number: true
                },
                dampShearStrain100: {
                    minNumber5: true,
                    number: true
                },
                dampShearStrain500: {
                    minNumber5: true,
                    number: true
                },
                dampShearStrain1000: {
                    minNumber5: true,
                    number: true
                },
                dampShearStrain5000: {
                    minNumber5: true,
                    number: true
                },
                dampShearStrain10000: {
                    minNumber5: true,
                    number: true
                },
            },
            messages: {
                specimenCode: {
                    maxlength: "不多于20个字符"
                },
                soilName: {
                    maxlength: "不多于20个字符"
                },
                modulusShearStrain005: {
                    required: "模量比(G/Gmax)剪应变(γ)（10-4×0.05)不允许为空!",
                },
                modulusShearStrain010: {
                    required: "模量比(G/Gmax)剪应变(γ)（10-4×0.10)不允许为空!",
                },
                modulusShearStrain050: {
                    required: "模量比(G/Gmax)剪应变(γ)（10-4×0.50)不允许为空!",
                },
                modulusShearStrain100: {
                    required: "模量比(G/Gmax)剪应变(γ)（10-4×1.00)不允许为空!",
                },
                modulusShearStrain500: {
                    required: "模量比(G/Gmax)剪应变(γ)（10-4×5.00)不允许为空!",
                },
                modulusShearStrain1000: {
                    required: "模量比(G/Gmax)剪应变(γ)（10-4×10.00)不允许为空!",
                },
                modulusShearStrain5000: {
                    required: "模量比(G/Gmax)剪应变(γ)（10-4×50.00)不允许为空!",
                },
                modulusShearStrain10000: {
                    required: "模量比(G/Gmax)剪应变(γ)（10-4×100.00)不允许为空!",
                },
                dampShearStrain005: {
                    required: "阻尼比(λ)剪应变(γ)（10-4×0.05)不允许为空!",
                },
                dampShearStrain010: {
                    required: "阻尼比(λ)剪应变(γ)（10-4×0.10)不允许为空!",
                },
                dampShearStrain050: {
                    required: "阻尼比(λ)剪应变(γ)（10-4×0.50)不允许为空!",
                },
                dampShearStrain100: {
                    required: "阻尼比(λ)剪应变(γ)（10-4×1.00)不允许为空!",
                },
                dampShearStrain500: {
                    required: "阻尼比(λ)剪应变(γ)（10-4×5.00)不允许为空!",
                },
                dampShearStrain1000: {
                    required: "阻尼比(λ)剪应变(γ)（10-4×10.00)不允许为空!",
                },
                dampShearStrain5000: {
                    required: "阻尼比(λ)剪应变(γ)（10-4×50.00)不允许为空!",
                },
                dampShearStrain10000: {
                    required: "阻尼比(λ)剪应变(γ)（10-4×100.00)不允许为空!",
                },
            }
        });
    };
    var formValidatorY18 = function () {
        $("#qhSiteCategoryForm").validate({
            rules: {
                siteType: {
                    required: true,
                },
            },
            messages: {
                siteType: {
                    required: "场地类别不允许为空!",
                },
            }
        });
    };
    var getQhDrillOverview = function (id) {
        $.ajax({
            url: getQhDrillOverviewController() + "/" + id,
            type: "get",
            success: function (data) {
                if (data.qualityOpinion) {
                    data.qualityOpinion = replaceMark(data.qualityOpinion);
                }
                editProvince(data.province, data.city, data.area);
                viewFileUpload(data.accessory);
                Tool.deserialize("qhDrillForm", data);
            }
        });
    };
    var replaceMark = function (str) {
        var index = str.indexOf(';');
        if (index > -1) {
            var f = str.substring(0, index);
            var s = str.substring(index + 1, str.length);
            str = f + "\r\n" + s;
            return replaceMark(str);
        } else {
            return str;
        }
    };
    //编辑页面附件
    var viewFileUpload = function (fileData) {
        require(['UtilDir/fileupload/multiFileUpload'], function (MFU) {
            var attachIdData = "";
            var attachId = "";
            var fileArray = "";
            if (fileData == null) {
                fileData = "";
            }
            if (fileData.length != 0) {
                fileArray = fileData.split(',');
                attachIdData = fileData.split(',');
            }
            var settings = {
                placeAt: "multiFileUpload",
                allowMC: false,
                fileSizeLimit: 1024 * 1024 * 1024,
                /*
	            1.0.2版本新增
	            extendColumn:[
	                {name:"文件分类",filed:"category",format:function(file){return file.name}},
	                {name:"备注",filed:"remark",format:function(file){return '机密'}}
	            ],*/
                data: attachIdData,
                onUploadSuccess: function (file) {
                    attachId += file.attachId + ",";
                    if (fileData.length == 0) {
                        $("#accessory").val(attachId.substr(0, attachId.length - 1));
                    } else {
                        $("#accessory").val(fileData + "," + attachId.substr(0, attachId.length - 1));
                    }

                },
                onDeleteSavedFile: function (file) {
                    var index = fileArray.indexOf(file.attachId);
                    fileArray.splice(index, 1);
                    $("#accessory").val(fileArray.toString());
                }
            };
            var MFUpload = MFU.init(settings);

        });
    };
    var editProvince = function (Province, City, Area) {
        debugger;
        var html = "";
        $("#city").append(html);
        $("#area").append(html);
        $.ajax({
            url: getServer() + "/divisions/root/subdivisions",
            contentType: "application/json",
            type: "get",
            success: function (data) {
                $.each(data, function (idx, item) {
                    if (item.divisionName == Province) {
                        debugger;
                        var divisionId = item.divisionId;
                        var htmlCity = '';
                        if (Province == "北京市" || Province == "天津市" || Province == "上海市" || Province == "重庆市") {
                            $("#city").append("<option value='" + Province + "' exid='" + divisionId + "'>" + Province + "</option>");
                            $('#city').val(City);
                            var htmlArea = '';
                            $.ajax({
                                url: getServer() + "/divisions/" + divisionId + "/subdivisions",
                                contentType: "application/json",
                                type: "get",
                                success: function (data) {
                                    $.each(data, function (idx, item) {
                                        htmlArea += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                                    });
                                    $("#area").append(htmlArea);
                                    $('#area').val(Area);
                                }
                            });

                        } else {
                            $.ajax({
                                url: getServer() + "/divisions/" + divisionId + "/subdivisions",
                                contentType: "application/json",
                                type: "get",
                                success: function (data) {
                                    debugger;
                                    $.each(data, function (idx, item) {
                                        if (item.divisionName == City) {
                                            var divisionId = item.divisionId;
                                            var htmlArea = '';
                                            $.ajax({
                                                url: getServer() + "/divisions/" + divisionId + "/subdivisions",
                                                contentType: "application/json",
                                                type: "get",
                                                success: function (data) {
                                                    $.each(data, function (idx, item) {
                                                        htmlArea += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                                                    });
                                                    $("#area").append(htmlArea);
                                                    $('#area').val(Area);
                                                }
                                            });
                                        }
                                        htmlCity += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                                    });
                                    $("#city").append(htmlCity);
                                    $('#city').val(City);
                                }
                            });
                        }
                    }
                    html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                });
                $("#province").append(html);
                $('#province').val(Province);
            }
        });
        $("#province").change(function () {
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#city option").remove();
            $("#city").append(html);
            $("#area option").remove();
            $("#area").append(html);
            var divisionId = $(this).find("option:selected").attr("exid");
            if ($(this).val() == "北京市" || $(this).val() == "天津市" || $(this).val() == "上海市" || $(this).val() == "重庆市") {
                $("#city").append("<option value='" + $(this).val() + "' exid='" + divisionId + "'>" + $(this).val() + "</option>");
                return;
            }
            $.ajax({
                url: getServer() + "/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#city").append(html);
                }
            });
        });
        $("#city").change(function () {
            if ($(this).val() == "") return;
            var html = '<option value="" disabled selected style="display:none;">请选择</option>';
            $("#area option").remove();
            $("#area").append(html);
            var divisionId = $(this).find("option:selected").attr("exid");
            $.ajax({
                url: getServer() + "/divisions/" + divisionId + "/subdivisions",
                contentType: "application/json",
                type: "get",
                success: function (data) {
                    $.each(data, function (idx, item) {
                        html += "<option value='" + item.divisionName + "' exid='" + item.divisionId + "'>" + item.divisionName + "</option>";
                    });
                    $("#area").append(html);
                }
            });
        });
    };
    //添加主表钻孔
    var addQhDrillOverview = function () {
        var slidebar = Util.slidebar({
            url: qhDrillFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                fileUpload();
                initProjectCompleteDate();
                initConstructionStartDate();
                initConstructionReportDate();
                initcreateProvinceForm();
                formValidator();
                $("#saveBtn").on("click", function () {
                    if ($("#qhDrillForm").valid()) {
                        var data = Tool.serialize("qhDrillForm");
                        if (!data.accessory) {
                            Util.alert("请上传附件");
                            return;
                        }
                        $.ajax({
                            url: getQhDrillOverviewController() + "/save",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createQhDrillOverviewGrid();
                            }
                        });
                    }
                });
            }
        });
    };
    //附件类型
    var FILE_TYPES = {
        image: {
            title: '图片文件',
            extensions: 'jpg,jpeg,bmp,png,ico',
            mimeTypes: 'image/bmp,image/jpeg,image/png,image/x-icon'
        },
        doc: {
            title: '文档文件',
            extensions: 'doc,docx,xls,xlsx,ppt,pptx,pdf',
            mimeTypes: 'application/vnd.ms-excel.12,application/vnd.ms-word.document.12,application/vnd.ms-powerpoint.12,' +
                'application/pdf,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/msword'
        },
        video: {
            title: '视频文件',
            extensions: 'mp4,avi,mov,mpg',
            mimeTypes: 'video/mpeg,video/quicktime,video/x-msvideo,'
                + 'application/vnd.rn-realmedia-vbr,video/mp4'
        },
        audio: {
            title: '音频文件',
            extensions: 'wma,mp3,wav',
            mimeTypes: 'audio/x-ms-wma,audio/mpeg,audio/x-wav'
        },
        packet: {
            titil: '压缩包',
            extensions: 'zip,rar',
            mimeTypes: 'application/zip,application/x-rar-compressed'
        }
    };
    //添加主表附件
    var fileUpload = function () {
        require(['UtilDir/fileupload/multiFileUpload'], function (MFU) {
            var attachId = "";
            var settings = {
                placeAt: "multiFileUpload",
                allowMC: false,
                fileSizeLimit: 1024 * 1024 * 1024,
                /*
	            1.0.2版本新增
	            extendColumn:[
	                {name:"文件分类",filed:"category",format:function(file){return file.name}},
	                {name:"备注",filed:"remark",format:function(file){return '机密'}}
	            ],*/
                //data:["5a50d697c0af806aa01e06120d04f977","6c01e4492f264befab4c0525811f8dff"],
                onUploadSuccess: function (file) {
                    attachId += file.attachId + ",";
                    $("#accessory").val(attachId.substr(0, attachId.length - 1));
                },
                onDeleteSavedFile: function (file) {
                    //console.log(file)
                }
            };
            var MFUpload = MFU.init(settings);

        });
    };
    //编辑主表钻孔
    window._editQhDrillOverview = function (qhDrillOverviewId, dataState) {
        var slidebar = Util.slidebar({
            url: qhDrillOverviewFormHtml,
            width: "1100px",
            cache: false,
            close: true,
            afterLoad: function () {
                if (dataState == "1" || dataState == "2" || dataState == "3" || dataState == "4") {
                    $('#commentsArea').show();
                }
                if (dataState == "4") {
                    $("#qhDrillForm").find("fieldset").attr("disabled", "disabled");
                    $("#saveBtn").hide();
                }
                initProjectCompleteDate();
                initConstructionStartDate();
                initConstructionReportDate();
                formValidator();
                getQhDrillOverview(qhDrillOverviewId);
                $("#saveBtn").on("click", function () {
                    if ($("#qhDrillForm").valid()) {
                        var data = Tool.serialize("qhDrillForm");
                        data.dataState = "0";
                        if (!data.accessory) {
                            Util.alert("请上传附件");
                            return;
                        }
                        $.ajax({
                            url: getQhDrillOverviewController() + "/update",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createQhDrillOverviewGrid();
                            }
                        });
                    }
                });
            },
            afterOpen: function () {
                //Y04地层岩性分布
                $("#lithologylab").on('shown.bs.tab', function (e) {
                    createLithologyGrid(qhDrillOverviewId, dataState);
                });
                //Y05标贯值
                $("#standardPenetrationlab").on('shown.bs.tab', function (e) {
                    createStandardPenetrationGrid(qhDrillOverviewId, dataState);
                });
                //Y06剪切波实测值
                $("#shearWavelab").on('shown.bs.tab', function (e) {
                    createShearWaveGrid(qhDrillOverviewId, dataState);
                });
                //Y08土动力试验参数
                $("#soilDynamiclab").on('shown.bs.tab', function (e) {
                    createSoilDynamicGrid(qhDrillOverviewId, dataState);
                });
                //Y18场地类别
                $("#siteCategorylab").on('shown.bs.tab', function (e) {
                    createSiteCategoryGrid(qhDrillOverviewId, dataState);
                });
            }
        });
    };
    //查看Y04地层岩性分布表格
    var createLithologyGrid = function (qhDrillOverviewId, dataState) {
        debugger
        $("#lithologyGrid").datagrid({
            url: QhY04Controller() + "/queryQhY04s",
            method: "GET",
            fitColumns: true,
            autoRowHeight: false,
            idField: 'id',
            columns: [[
                {field: "ck", checkbox: true},
                {
                    field: 'assiseNumber',
                    title: '<span style="color:red;">*</span>地层序号',
                    width: '15%',
                    sortable: true,
                    align: 'center',

                },
                {
                    field: 'assiseCode',
                    title: '地层编号',
                    width: '15%',
                    align: 'center',

                },
                {
                    field: 'formationAge',
                    title: '<span style="color:red;">*</span>地层年代',
                    width: '13%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'causeAge',
                    title: '时代成因',
                    width: '13%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'bottomDepth',
                    title: '<span style="color:red;">*</span>层底深度（m）',
                    width: '15%',
                    sortable: true,
                    align: 'center',

                },
                {
                    field: 'layerThickness',
                    title: '<span style="color:red;">*</span>分层厚度（m）',
                    width: '15%',
                    align: 'center',

                },
                {
                    field: 'geotechnicalName',
                    title: '<span style="color:red;">*</span>岩土名称',
                    width: '15%',
                    align: 'center',

                },
                {
                    field: 'geotechnicalCharacteristics',
                    title: '<span style="color:red;">*</span>岩土特征',
                    width: '15%',
                    align: 'center',

                },
                {
                    field: 'operation', title: '操作', width: '12%', align: 'center',
                    formatter: function (value, rowData, rowIndex) {
                        return '<a href="#" onclick="_viewLithology(\'' + rowData.id + "','" + qhDrillOverviewId + "','" + dataState + '\');">查看详情</a> '
                    }
                }
            ]],
            toolbar: [{
                iconCls: 'fa fa-plus-circle',
                text: "添加",
                handler: function () {
                    addQhLithologyGrid(qhDrillOverviewId);
                }
            }, {
                iconCls: 'fa fa-trash-o',
                text: "删除",
                handler: function () {
                    deleteQhLithologyGrid(qhDrillOverviewId);
                }
            }],
            queryParams: {
                drillId: qhDrillOverviewId,
            },
            pagination: true,
            pageSize: 10
        });
    }
    //添加Y04地层岩性分布
    var addQhLithologyGrid = function (qhDrillOverviewId) {
        debugger
        var slidebar = Util.slidebar({
            url: qhLithologyFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                formValidatorY04();
                $("#saveLithologyBtn").on("click", function () {
                    if ($("#qhLithologyForm").valid()) {
                        $("#drillId").val(qhDrillOverviewId);
                        var data = Tool.serialize("qhLithologyForm");
                        $.ajax({
                            url: QhY04Controller() + "/save",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createLithologyGrid(qhDrillOverviewId);
                            }
                        });
                    }
                });
            }
        });
    };
    //查看Y04地层岩性分布详情
    window._viewLithology = function (lithologyId, qhDrillOverviewId, dataState) {
        var slidebar = Util.slidebar({
            url: qhLithologyFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                if (dataState == "4") {
                    $("#qhLithologyForm").find("fieldset").attr("disabled", "disabled");
                    $("#saveLithologyBtn").hide();
                }
                formValidatorY04();
                getLithology(lithologyId);
                $("#saveLithologyBtn").on("click", function () {
                    if ($("#qhLithologyForm").valid()) {
                        var data = Tool.serialize("qhLithologyForm");
                        $.ajax({
                            url: QhY04Controller() + "/update",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createLithologyGrid(qhDrillOverviewId);
                                createQhDrillOverviewGrid();
                            }
                        });
                    }
                });
            }
        });
    };
    var getLithology = function (id) {
        $.ajax({
            url: QhY04Controller() + "/" + id,
            type: "get",
            success: function (data) {
                Tool.deserialize("qhLithologyForm", data);
            }
        });
    };
    //删除Y04地层岩性分布
    var deleteQhLithologyGrid = function (qhDrillOverviewId) {
        var rows = $("#lithologyGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        }
        Util.confirm("是否要删除选中的数据?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";

            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: QhY04Controller() + "/delete",
                contentType: "application/json",
                data: ids,
                type: "post",
                success: function (data) {
                    createLithologyGrid(qhDrillOverviewId);
                }
            });
        }, function () {
            return;
        });

    };
    //查看Y05标贯值表格
    var createStandardPenetrationGrid = function (qhDrillOverviewId, dataState) {
        debugger
        $("#standardPenetrationGrid").datagrid({
            url: QhY05Controller() + "/queryQhY05s",
            method: "GET",
            fitColumns: true,
            autoRowHeight: false,
            idField: 'id',
            columns: [[
                {field: "ck", checkbox: true},
                {
                    field: 'standardStartDepth',
                    title: '起始标贯深度(m)',
                    width: '25%',
                    sortable: true,
                    align: 'center',

                },
                {
                    field: 'standardEndDepth',
                    title: '结束标贯深度(m)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'standardNumber',
                    title: '标贯值',
                    width: '25%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'operation', title: '操作', width: '24%', align: 'center',
                    formatter: function (value, rowData, rowIndex) {
                        return '<a href="#" onclick="_viewStandardPenetration(\'' + rowData.id + "','" + qhDrillOverviewId + "','" + dataState + '\');">查看详情</a> '
                    }
                }
            ]],
            toolbar: [{
                iconCls: 'fa fa-plus-circle',
                text: "添加",
                handler: function () {
                    addQhStandardPenetrationGrid(qhDrillOverviewId);
                }
            }, {
                iconCls: 'fa fa-trash-o',
                text: "删除",
                handler: function () {
                    deleteQhStandardPenetrationGrid(qhDrillOverviewId);
                }
            }],
            queryParams: {
                drillId: qhDrillOverviewId,
            },
            pagination: true,
            pageSize: 10
        });
    }
    //添加Y05标贯值
    var addQhStandardPenetrationGrid = function (qhDrillOverviewId) {
        debugger
        var slidebar = Util.slidebar({
            url: qhStandardPenetrationFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                formValidatorY05();
                $("#saveStandardPenetrationBtn").on("click", function () {
                    debugger
                    if ($("#qhStandardPenetrationForm").valid()) {
                        debugger
                        $("#drillId").val(qhDrillOverviewId);
                        var data = Tool.serialize("qhStandardPenetrationForm");
                        $.ajax({
                            url: QhY05Controller() + "/save",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createStandardPenetrationGrid(qhDrillOverviewId);
                            }
                        });
                    }
                });
            }
        });
    };
    //查看Y05标贯值
    window._viewStandardPenetration = function (StandardPenetrationId, qhDrillOverviewId, dataState) {
        var slidebar = Util.slidebar({
            url: qhStandardPenetrationFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                if (dataState == "4") {
                    $("#qhStandardPenetrationForm").find("fieldset").attr("disabled", "disabled");
                    $("#saveStandardPenetrationBtn").hide();
                }
                formValidatorY05();
                getStandardPenetration(StandardPenetrationId);
                $("#saveStandardPenetrationBtn").on("click", function () {
                    if ($("#qhStandardPenetrationForm").valid()) {
                        var data = Tool.serialize("qhStandardPenetrationForm");
                        $.ajax({
                            url: QhY05Controller() + "/update",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createStandardPenetrationGrid(qhDrillOverviewId);
                                createQhDrillOverviewGrid();
                            }
                        });
                    }
                });
            }
        });
    };
    var getStandardPenetration = function (id) {
        $.ajax({
            url: QhY05Controller() + "/" + id,
            type: "get",
            success: function (data) {
                Tool.deserialize("qhStandardPenetrationForm", data);
            }
        });
    };
    //删除Y05标贯值
    var deleteQhStandardPenetrationGrid = function (qhDrillOverviewId) {
        var rows = $("#standardPenetrationGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        }
        Util.confirm("是否要删除选中的数据?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";

            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: QhY05Controller() + "/delete",
                contentType: "application/json",
                data: ids,
                type: "post",
                success: function (data) {
                    createStandardPenetrationGrid(qhDrillOverviewId);
                }
            });
        }, function () {
            return;
        });

    };
    //查看Y06剪切波实测值表格
    var createShearWaveGrid = function (qhDrillOverviewId, dataState) {
        debugger
        $("#shearWaveGrid").datagrid({
            url: QhY06Controller() + "/queryQhY06s",
            method: "GET",
            fitColumns: true,
            autoRowHeight: false,
            idField: 'id',
            columns: [[
                {field: "ck", checkbox: true},
                {
                    field: 'code',
                    title: '<span style="color:red;">*</span>序号',
                    width: '12%',
                    sortable: true,
                    align: 'center',

                },
                {
                    field: 'geotechnicalDesignation',
                    title: '<span style="color:red;">*</span>岩土性名称',
                    width: '18%',
                    align: 'center',

                },
                {
                    field: 'bottomDepth',
                    title: '<span style="color:red;">*</span>层底深度 (m)',
                    width: '16%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'layerThickness',
                    title: '<span style="color:red;">*</span>层厚(m)',
                    width: '16%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'shearWaveVelocity',
                    title: '<span style="color:red;">*</span>剪切波波速V(m/s)',
                    width: '18%',
                    sortable: true,
                    align: 'center',

                },
                {
                    field: 'operation', title: '操作', width: '15%', align: 'center',
                    formatter: function (value, rowData, rowIndex) {
                        return '<a href="#" onclick="_viewShearWave(\'' + rowData.id + "','" + qhDrillOverviewId + "','" + dataState + '\');">查看详情</a> '
                    }
                }
            ]],
            toolbar: [{
                iconCls: 'fa fa-plus-circle',
                text: "添加",
                handler: function () {
                    addQhShearWaveGrid(qhDrillOverviewId);
                }
            }, {
                iconCls: 'fa fa-trash-o',
                text: "删除",
                handler: function () {
                    deleteQhShearWaveGrid(qhDrillOverviewId);
                }
            }],
            queryParams: {
                drillId: qhDrillOverviewId,
            },
            pagination: true,
            pageSize: 10
        });
    }
    //添加Y06剪切波实测值
    var addQhShearWaveGrid = function (qhDrillOverviewId) {
        debugger
        var slidebar = Util.slidebar({
            url: qhShearWaveFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                formValidatorY06();
                $("#saveShearWaveBtn").on("click", function () {
                    if ($("#qhShearWaveForm").valid()) {
                        $("#drillId").val(qhDrillOverviewId);
                        var data = Tool.serialize("qhShearWaveForm");
                        $.ajax({
                            url: QhY06Controller() + "/save",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createShearWaveGrid(qhDrillOverviewId);
                            }
                        });
                    }
                });
            }
        });
    };
    //查看Y06剪切波实测值
    window._viewShearWave = function (ShearWaveId, qhDrillOverviewId, dataState) {
        var slidebar = Util.slidebar({
            url: qhShearWaveFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                if (dataState == "4") {
                    $("#qhShearWaveForm").find("fieldset").attr("disabled", "disabled");
                    $("#saveShearWaveBtn").hide();
                }
                formValidatorY06();
                getShearWave(ShearWaveId);
                $("#saveShearWaveBtn").on("click", function () {
                    if ($("#qhShearWaveForm").valid()) {
                        var data = Tool.serialize("qhShearWaveForm");
                        $.ajax({
                            url: QhY06Controller() + "/update",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createShearWaveGrid(qhDrillOverviewId);
                                createQhDrillOverviewGrid();
                            }
                        });
                    }
                });
            }
        });
    };
    var getShearWave = function (id) {
        $.ajax({
            url: QhY06Controller() + "/" + id,
            type: "get",
            success: function (data) {
                Tool.deserialize("qhShearWaveForm", data);
            }
        });
    };
    //删除Y06剪切波实测值
    var deleteQhShearWaveGrid = function (qhDrillOverviewId) {
        var rows = $("#shearWaveGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        }
        Util.confirm("是否要删除选中的数据?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";

            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: QhY06Controller() + "/delete",
                contentType: "application/json",
                data: ids,
                type: "post",
                success: function (data) {
                    createShearWaveGrid(qhDrillOverviewId);
                }
            });
        }, function () {
            return;
        });

    };
    //查看Y08土动力试验参数表格
    var createSoilDynamicGrid = function (qhDrillOverviewId, dataState) {
        debugger
        $("#soilDynamicGrid").datagrid({
            url: QhY08Controller() + "/queryQhY08s",
            method: "GET",
            fitColumns: true,
            autoRowHeight: false,
            idField: 'id',
            columns: [[
                {field: "ck", checkbox: true},
                {
                    field: 'code',
                    title: '序号',
                    width: '12%',
                    sortable: true,
                    align: 'center',

                },
                {
                    field: 'specimenCode',
                    title: '样品编号',
                    width: '15%',
                    align: 'center',

                },
                {
                    field: 'specimenStartDepth',
                    title: '取样深度顶点(m)',
                    width: '15%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'specimenEndDepth',
                    title: '取样深度底点(m)',
                    width: '15%',
                    sortable: true,
                    align: 'center',
                },
                {
                    field: 'soilName',
                    title: '土层名称',
                    width: '15%',
                    align: 'center',

                },
                {
                    field: 'naturalDensity',
                    title: '密度(kg/m3)',
                    width: '15%',
                    align: 'center',

                },
                {
                    field: 'modulusShearStrain005',
                    title: '模量比(G/Gmax)剪应变(γ)（10-4×0.05)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'modulusShearStrain010',
                    title: '模量比(G/Gmax)剪应变(γ)（10-4×0.10)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'modulusShearStrain050',
                    title: '模量比(G/Gmax)剪应变(γ)（10-4×0.50)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'modulusShearStrain100',
                    title: '模量比(G/Gmax)剪应变(γ)（10-4×1.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'modulusShearStrain500',
                    title: '模量比(G/Gmax)剪应变(γ)（10-4×5.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'modulusShearStrain1000',
                    title: '模量比(G/Gmax)剪应变(γ)（10-4×10.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'modulusShearStrain5000',
                    title: '模量比(G/Gmax)剪应变(γ)（10-4×50.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'modulusShearStrain10000',
                    title: '模量比(G/Gmax)剪应变(γ)（10-4×100.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'dampShearStrain005',
                    title: '阻尼比(λ)剪应变(γ)（10-4×0.05)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'dampShearStrain010',
                    title: '阻尼比(λ)剪应变(γ)（10-4×0.10)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'dampShearStrain050',
                    title: '阻尼比(λ)剪应变(γ)（10-4×0.50)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'dampShearStrain100',
                    title: '阻尼比(λ)剪应变(γ)（10-4×1.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'dampShearStrain500',
                    title: '阻尼比(λ)剪应变(γ)（10-4×5.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'dampShearStrain1000',
                    title: '阻尼比(λ)剪应变(γ)（10-4×10.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'dampShearStrain5000',
                    title: '阻尼比(λ)剪应变(γ)（10-4×50.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'dampShearStrain10000',
                    title: '阻尼比(λ)剪应变(γ)（10-4×100.00)',
                    width: '25%',
                    align: 'center',

                },
                {
                    field: 'operation', title: '操作', width: '12%', align: 'center',
                    formatter: function (value, rowData, rowIndex) {
                        return '<a href="#" onclick="_viewSoilDynamic(\'' + rowData.id + "','" + qhDrillOverviewId + "','" + dataState + '\');">查看详情</a> '
                    }
                }
            ]],
            toolbar: [{
                iconCls: 'fa fa-plus-circle',
                text: "添加",
                handler: function () {
                    addQhSoilDynamicGrid(qhDrillOverviewId);
                }
            }, {
                iconCls: 'fa fa-trash-o',
                text: "删除",
                handler: function () {
                    deleteQhSoilDynamicGrid(qhDrillOverviewId);
                }
            }],
            queryParams: {
                drillId: qhDrillOverviewId,
            },
            pagination: true,
            pageSize: 10
        });
    }
    //添加Y08土动力试验参数
    var addQhSoilDynamicGrid = function (qhDrillOverviewId) {
        debugger
        var slidebar = Util.slidebar({
            url: qhSoilDynamicFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                formValidatorY08();
                $("#saveSoilDynamicBtn").on("click", function () {
                    if ($("#qhSoilDynamicForm").valid()) {
                        $("#drillId").val(qhDrillOverviewId);
                        var data = Tool.serialize("qhSoilDynamicForm");
                        $.ajax({
                            url: QhY08Controller() + "/save",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createSoilDynamicGrid(qhDrillOverviewId);
                            }
                        });
                    }
                });
            }
        });
    };
    //查看Y08土动力试验参数详情
    window._viewSoilDynamic = function (soilDynamicId, qhDrillOverviewId, dataState) {
        var slidebar = Util.slidebar({
            url: qhSoilDynamicFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                if (dataState == "4") {
                    $("#qhSoilDynamicForm").find("fieldset").attr("disabled", "disabled");
                    $("#saveSoilDynamicBtn").hide();
                }
                formValidatorY08();
                getSoilDynamic(soilDynamicId);
                $("#saveSoilDynamicBtn").on("click", function () {
                    if ($("#qhSoilDynamicForm").valid()) {
                        var data = Tool.serialize("qhSoilDynamicForm");
                        $.ajax({
                            url: QhY08Controller() + "/update",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createSoilDynamicGrid(qhDrillOverviewId);
                                createQhDrillOverviewGrid();
                            }
                        });
                    }
                });
            }
        });
    };
    var getSoilDynamic = function (id) {
        $.ajax({
            url: QhY08Controller() + "/" + id,
            type: "get",
            success: function (data) {
                Tool.deserialize("qhSoilDynamicForm", data);
            }
        });
    };
    //删除Y08土动力试验参数
    var deleteQhSoilDynamicGrid = function (qhDrillOverviewId) {
        var rows = $("#soilDynamicGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        }
        Util.confirm("是否要删除选中的数据?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";

            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: QhY08Controller() + "/delete",
                contentType: "application/json",
                data: ids,
                type: "post",
                success: function (data) {
                    createSoilDynamicGrid(qhDrillOverviewId);
                }
            });
        }, function () {
            return;
        });

    };
    //查看Y18场地类别表格
    var createSiteCategoryGrid = function (qhDrillOverviewId, dataState) {
        debugger
        $("#siteCategoryGrid").datagrid({
            url: QhY18Controller() + "/queryQhY18s",
            method: "GET",
            fitColumns: true,
            autoRowHeight: false,
            idField: 'id',
            columns: [[
                {field: "ck", checkbox: true},
                {
                    field: 'siteType',
                    title: '<span style="color:red;">*</span>场地类别',
                    width: '50%',
                    align: 'center',

                },
                {
                    field: 'operation', title: '操作', width: '48%', align: 'center',
                    formatter: function (value, rowData, rowIndex) {
                        return '<a href="#" onclick="_viewSiteCategory(\'' + rowData.id + "','" + qhDrillOverviewId + "','" + dataState + '\');">查看详情</a> '
                    }
                }
            ]],
            toolbar: [{
                iconCls: 'fa fa-plus-circle',
                text: "添加",
                handler: function () {
                    addQhSiteCategoryGrid(qhDrillOverviewId);
                }
            }, {
                iconCls: 'fa fa-trash-o',
                text: "删除",
                handler: function () {
                    deleteQhSiteCategoryGrid(qhDrillOverviewId);
                }
            }],
            queryParams: {
                drillId: qhDrillOverviewId,
            },
            pagination: true,
            pageSize: 10
        });
    }
    //添加Y18场地类别
    var addQhSiteCategoryGrid = function (qhDrillOverviewId) {
        debugger
        var slidebar = Util.slidebar({
            url: qhSiteCategoryFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                formValidatorY18();
                $("#saveSiteCategoryBtn").on("click", function () {
                    debugger
                    if ($("#qhSiteCategoryForm").valid()) {
                        debugger
                        $("#drillId").val(qhDrillOverviewId);
                        var data = Tool.serialize("qhSiteCategoryForm");
                        $.ajax({
                            url: QhY18Controller() + "/save",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createSiteCategoryGrid(qhDrillOverviewId);
                            }
                        });
                    }
                });
            }
        });
    };
    //查看Y18场地类别
    window._viewSiteCategory = function (siteCategoryId, qhDrillOverviewId, dataState) {
        var slidebar = Util.slidebar({
            url: qhSiteCategoryFormHtml,
            width: "900px",
            cache: false,
            close: true,
            afterLoad: function () {
                if (dataState == "4") {
                    $("#qhSiteCategoryForm").find("fieldset").attr("disabled", "disabled");
                    $("#saveSiteCategoryBtn").hide();
                }
                formValidatorY18();
                getSiteCategory(siteCategoryId);
                $("#saveSiteCategoryBtn").on("click", function () {
                    if ($("#qhSiteCategoryForm").valid()) {
                        var data = Tool.serialize("qhSiteCategoryForm");
                        $.ajax({
                            url: QhY18Controller() + "/update",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            type: "post",
                            success: function (data) {
                                Util.alert(data.message);
                                slidebar.close();
                                createSiteCategoryGrid(qhDrillOverviewId);
                                createQhDrillOverviewGrid();
                            }
                        });
                    }
                });
            }
        });
    };
    var getSiteCategory = function (id) {
        $.ajax({
            url: QhY18Controller() + "/" + id,
            type: "get",
            success: function (data) {
                Tool.deserialize("qhSiteCategoryForm", data);
            }
        });
    };
    //删除Y18场地类别
    var deleteQhSiteCategoryGrid = function (qhDrillOverviewId) {
        var rows = $("#siteCategoryGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        }
        Util.confirm("是否要删除选中的数据?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";

            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: QhY18Controller() + "/delete",
                contentType: "application/json",
                data: ids,
                type: "post",
                success: function (data) {
                    createSiteCategoryGrid(qhDrillOverviewId);
                }
            });
        }, function () {
            return;
        });

    };
    //删除主表钻孔
    var deleteQhDrillOverview = function () {
        var rows = $("#qhDrillOverviewGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        }
        Util.confirm("是否要删除选中的数据?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";

            });
            ids = ids.substr(0, ids.length - 1);
            $.ajax({
                url: getQhDrillOverviewController() + "/delete",
                contentType: "application/json",
                data: ids,
                type: "post",
                success: function (data) {
                    createQhDrillOverviewGrid();
                }
            });
        }, function () {
            return;
        });

    };
    //导入
    var importForm = function () {

        $("#uploadModal").modal();
        $("#uploadModal").on("shown.bs.modal", function () {
            var url = getServer() + "/fw/brick/downMould";
            $("#downloadZwExcelTemplate").attr("href", url);
        });

        $('#uploadButton').off("click");
        $("#uploadButton").on("click", function () {
            var uploadinput = document.getElementById("uploadFile");
            if (uploadinput.value == "") {
                Util.alert("上传前请先选择文件!");
                return;
            }
            var formData = new FormData();
            formData.append("file", uploadinput.files[0]);
            $.ajax({
                url: getMutipleSheetPoiController() + "/importMultiSheet",
                data: formData,
                processData: false, //因为data值是FormData对象，不需要对数据做处理。
                contentType: false,
                type: "POST",
                success: function (data) {
                    $('#uploadModal').modal('hide');
                    uploadinput.value = null;
                    Util.alert(data);
                    createQhDrillOverviewGrid()
                }
            });
        });
    };
    //导出
    var exportForm = function () {
        var rows = $("#qhDrillOverviewGrid").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            Util.alert("请选择一行数据!");
            return;
        }
        Util.confirm("是否要导出选中的表单?", function () {
            var ids = "";
            $.each(rows, function (i, row) {
                ids += row.id + ",";
            });
            ids = ids.substr(0, ids.length - 1);
            window.location.href = getMutipleSheetPoiController() + "/exportMultiSheet/" + ids;
        }, function () {
            return;
        });
        //window.location.href = getQhDrillOverviewController() + "/exportFile";
    };

    return {
        init: init
    };
});
